<?php
/**
 * HouseReco controller
 */
namespace App\Http\ControllersAdmin;

use App\Service\HouseRecoService;
use App\Validation\HouseSecoValidation;
use App\Validation\HouseSearchValidation;
use App\Validation\DeleteValidation;
use App\Validation\BatchValidation;

class HouseRecoController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new HouseSearchValidation, $this->request->getJsonRawBody());
		// $raw->city_id = $this->city_id;

		$data = HouseRecoService::getSearch($raw);
		$d = [];
		foreach ($data as $key => $value) {
			$d[$key] = $value;
			$d[$key]->area = $value->area ? $value->area:"面积未知";
			$d[$key]->price = $value->price ? $value->price : "面议";
			unset($d[$key]->unit);
			$d[$key]->go_url = $this->config->gourl . $this->config->urls->house_seco . $value->id;
		}		
		$count = HouseRecoService::getSearch($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $d
		];
		return $this->echoJson($assign);
	}

	/**
	 * [stickAction 置顶]
	 * @return [type] [description]
	 */
	public function stickAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		HouseRecoService::getStick($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [upAction 上架]
	 * @return [type] [description]
	 */
	public function displayAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = HouseRecoService::display($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = HouseRecoService::delete($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [foreverAction 彻底删除]
	 * @return [type] [description]
	 */
	public function foreverAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = HouseRecoService::forever($raw->id);
		return $this->echoJson('ok');
	}
}